package com.ody.util.code.model;

import java.util.List;

public class CachedModelProvider implements IModelProvider {
	private IModelProvider modelProvider;
	private volatile List<Model> cachedModels;
	
	public CachedModelProvider(IModelProvider modelProvider) {
		this.modelProvider = modelProvider;
	}

	public IModelProvider getModelProvider() {
		return modelProvider;
	}

	@Override
	public List<Model> provide() {
		if (cachedModels == null) {
			synchronized (this) {
				if (cachedModels == null) {
					cachedModels = modelProvider.provide();
				}
			}
		}
		return cachedModels;
	}

}
